package com.q.tqb.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Description:
 * <p>
 * Author: gpw
 * Date: 2017/12/21
 */
public class VersionUtil {
    /**
     * 返回当前程序版本名
     */
    public static int getAppVersionName(Context context) {
        String versionName = "";
        int versioncode = 1;
        try {
            // ---get the package info---
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
            versioncode = pi.versionCode;
//            if (versionName == null || versionName.length() <= 0) {
//                return 1;
//            }

        } catch (Exception e) {
            // Log.e("VersionInfo", "Exception", e);
        }
        return versioncode;
    }
}
